// register script

$('input[type="submit"]').click(function () {
    var login = $('input[name="loginR"]').val();
    var pwd2 = $('input[name="pwd2R"]').val();
    var pwd = $('input[name="pwd1R"]').val();
    var tel = $('input[name="telNumberR"]').val();
    var code = $('input[name="codeR"]').val();
    var JsonDataR = {login: login, pwd: pwd, tel: tel, code: code,};
    //此处做为ajax内部判断
    var url = "";
      if ( JsonData.code.toUpperCase() == "2345") {
                url = "Ajax/Register";

            } else {
                url = "Ajax/RegisterFalse";
            }
    AjaxPost(url, JsonDataR,
        function () {
            //ajax加载中
        },
        function (data) {
        })
})

if (ajaxmockjax == 1) {
    $.mockjax({
        url: 'Ajax/Register',
        status: 200,
        responseTime: 50,
        responseText: {
            "Status": "ok", "Text": "注册成功<script>window.top.location = 'http://localhost:63342/FriendsSpace/templates/users/login.html?_ijt=u9ocson8rn831fike1op9c3a1';</script>",

        }

    });
    $.mockjax({
        url: 'Ajax/RehisterFalse',
        status: 200,
        responseTime: 50,
        responseText: {"Status": "Erro", "Erro": "注册出错"}
    });


}

function vUsename() {
    var login = $('input[name="loginR"]').val();
    var re = /^[a-zA-Z_]{6,18}$/;
    if (login == "") {
        ErroAlert("请输入用户名");
    } else if (login.length < 6 || login.length > 18) {
        ErroAlert("格式错误,长度应为6-18个字符");
    } else if (!re.test(login)) {

        ErroAlert("格式错误,只能包含英文字母和下划线");
    }

}


function vPassword() {
    var pwd2 = $('input[name="pwd2R"]').val();
    var pwd = $('input[name="pwd1R"]').val();
    var re = /^(?=.*\d)(?=.*[a-zA-Z])[\da-zA-Z]{6,}$/;
    // var reg=/[A-Za-z].*[0-9]|[0-9].*[A-Za-z]/;

    if (pwd == "") {
        ErroAlert('请输入密码');

    } else if (pwd.length < 6) {
        ErroAlert('格式错误,,密码长度至少为6位');
    } else if (!re.test(pwd)) {
        ErroAlert('格式错误,必须包含英文字母大小写和数字');

    }
}

function vPassword1() {
    var pwd2 = $('input[name="pwd2R"]').val();
    var pwd = $('input[name="pwd1R"]').val();
    if (pwd2 == '' || pwd != pwd2) {
        ErroAlert('请二次确认密码');
    }
}


function vTel() {
    var tel = $('input[name="telNumberR"]').val();

    var re = /^1\d{10}$/;
    if (tel == "") {
        ErroAlert("请输入联系电话");
    } else if (!re.test(tel)) {
        ErroAlert("电话格式输入错误");
    }
}

function vCode() {
    var code = $('input[name="codeR"]').val();
    if (code == '' || code.length != 4) {
        ErroAlert('输入正确的验证码');
    }

}